from functools import wraps
import datetime


def log_it(func):
    @wraps(func)
    def with_logging(*args, **kwargs):
        print(func.__name__, "was called at", datetime.datetime.now())
        return func(*args, **kwargs)

    return with_logging


@log_it
def addition_func(x):
    return x + x


result = addition_func(4)
print(result)


def logit(logfile="out.log"):
    def logging_decorator(func):
        @wraps(func)
        def wrapped_function(*args, **kwargs):
            log_string = func.__name__ + " was called"
            print(log_string)
            with open(logfile, "a") as opened_file:
                opened_file.writelines(log_string + "\n")
                # opened_file.write(log_string+"\n")
            return func(*args, **kwargs)

        return wrapped_function

    return logging_decorator


@logit()
def myfunc1():
    pass


myfunc1()


@logit(logfile="func2.log")
def myfunc2():
    pass


myfunc2()
